def ok(s):
    for i in xrange(1, 10):
        if str(i) not in s:
            return False
    return True
ans = 0
m = 1
while 1:
    n = 2
    while 1:
        s = ''
        for i in xrange(1, n + 1):
            s += str(m * i )
        if len(s) < 9:
            n += 1
            continue
        if len(s) > 9:
            break
        if ok(s):
            sn = int(s)
            if ans < sn:
                ans = sn
        n += 1
    if n == 2:
        break
    print 'm is %d' % m
    m += 1

print ans

